<?php
	
	class Admin_MembersController extends  BigsLibrary_Controller_Action{
		//Ham set layout admin
		public function init(){      
			$template_path = TEMPLATE_PATH . "/admin/default";
			$this->loadTemplate($template_path,'template.ini','admin');
            
		}
		
		public function membersAction(){
		  /*$p=new BigsLibrary_Controller_Pager();
          $limit=20;
		  $start=$p->findStart($limit);
		  $Person = new Admin_Model_Person();
          $count=count($Person->listPerson()->toArray());
          $pages=$p->findPages($count, $limit);
          
          //$this->view->lstMembers=$Person->listMembers(1,5);
          
          $this->view->lstMembers=$Person->listMembers($start,$limit);
          if(isset($_REQUEST['page']))
          {
		      $this->view->pagelist=$p->pageList($_REQUEST['page'],$pages);
          }else
          {
                $this->view->pagelist=$p->pageList(1,$pages);
          }*/
                             
          $base = $this->_request->getBaseUrl();
          $this->view->base=$base;
          $mRole=new Admin_Model_Role();
          $this->view->lstRole=$mRole->listRole(); 
          
          
		}
        public function lstAction(){
            //Lấy danh sách Member
            $mperson = new Admin_Model_Person();
            $t = $this->_request->getParam('type',1);
            $txt = $this->_request->getParam('text',1);
            $role = $this->_request->getParam('role',1);
            if($txt=="Search..."){
                $txt="";
            }
            
            $data = $mperson->listMember($t,$txt,$role);            
            //Lấy Base URL
            $this->view->base=$this->_request->getBaseUrl();
        
            //Đưa danh sách Member vào Zend_Paginator để bắt đầu phân trang
            $paginator = Zend_Paginator::factory($data);
        
            //Số user trên một trang
            $paginator->setItemCountPerPage(15);
        
            //Số trang được hiện ra để click
            $paginator->setPageRange(3);
        
            //Lấy trang hiện tại
            $currentPage = $this->_request->getParam('page',1);
            $paginator->setCurrentPageNumber($currentPage);
        
            //Truyền dữ liệu ra view
            $this->view->data=$paginator;
        
            //Không load layout
            $this->_helper->layout->disableLayout();
        }
        public function memberAction(){
            if(isset($_REQUEST["do"])&&$_REQUEST["do"]=="edit")
            {
                $mperson = new Admin_Model_Person();
                $muser = new Admin_Model_User();
                $user=$muser->getUser($_REQUEST["id"]);
                
                $person=$mperson->getPersonUser($_REQUEST["id"]);
                //select user
                $this->view->idUser=$user['IDUSER'];
                $this->view->nickname=$user['NICKNAME'];
                $this->view->role=$user['IDROLE'];
                $this->view->pass=$user['PASS'];
                $this->view->idfb=$user['IDFACEBOOK'];
                $this->view->idtwitter=$user['IDTWITTER'];
                $this->view->idgmail=$user['IDGMAIL'];
                $this->view->idyahoo=$user['IDYAHOO'];
                //select person
                $this->view->idPerson=$person['IDPERSON'];
                $this->view->Province=$person['IDPROVINCE'];
                $this->view->lastName=$person['LASTNAME'];
                $this->view->firstName=$person['FIRSTNAME'];
                $this->view->birthday=$person['BIRTHDAY'];
                $this->view->birthplace=$person['BIRTHPLACE'];
                $this->view->gender=$person['GENDER'];
                $this->view->address=$person['ADDRESS'];
                $this->view->email=$person['EMAIL'];
                $this->view->phone=$person['PHONE'];
                $this->view->lat=$person['LATPERSON'];
                $this->view->lng=$person['LNGPERSON'];
                $this->view->avatar=$person['AVATAR'];
               // var_dump($person);
//                die();
            }
			
		}
		
	}
	
?>